# coding=utf-8
from PO.BasePage import Base
from appium import webdriver


# 在行首页
class IndexPage(Base):
    """首页页面元素组件"""
    se_loc = ('id', 'com.guokr.mentor:id/text_view_search')
    work_loc = ('xpath',
                '//android.widget.GridView[@resource-id="com.guokr.mentor:id/grid_view_category_list"]/android.widget.RelativeLayout[1]')
    internet_loc = ('path',
                    '//android.widget.GridView[@resource-id="com.guokr.mentor:id/grid_view_category_list"]/android.widget.RelativeLayout[2]')
    life_loc = ('xpath',
                '//android.widget.GridView[@resource-id="com.guokr.mentor:id/grid_view_category_list"]/android.widget.RelativeLayout[3]')
    psy_loc = ('xpath',
               '//android.widget.GridView[@resource-id="com.guokr.mentor:id/grid_view_category_list"]/android.widget.RelativeLayout[4]')
    tech_loc = ('xpath',
                '//android.widget.GridView[@resource-id="com.guokr.mentor:id/grid_view_category_list"]/android.widget.RelativeLayout[5]')
    city_loc = ('id', 'com.guokr.mentor:id/text_view_city')
    msg_loc = ('id', 'com.guokr.mentor:id/image_view_message_center_list_entrance')
    home_page_loc = ('id', 'com.guokr.mentor:id/image_view_home_page_fg')
    discover_page_loc = ('id', 'com.guokr.mentor:id/image_view_discovery_bg')
    me_page_loc = ('id', 'com.guokr.mentor:id/image_view_personal_center_bg')

    def search(self):
        """搜索框"""
        self.find_element(self.se_loc).click()

    def workplace(self):
        """职场发展"""
        self.find_element(self.work_loc).click()

    def city(self):
        """城市选择"""
        self.find_element(self.city_loc).click()

    def cityShow(self):
        """城市显示"""
        return self.find_element(self.city_loc).text

    def msgCenter(self):
        """消息中心"""
        self.find_element(self.msg_loc).click()

    def home_page(self):
        """首页"""
        return self.find_element(self.home_page_loc)

    # def discover_page(self):
    #     """发现"""
    #     self.find_element(self.discover_page_loc).click()
    #
    # def me_page(self):
    #     """我的"""
    #     self.find_element(self.me_page_loc).click()


if __name__ == '__main__':
    capabilities = {'platformName': 'Android',
                    'platformVersion': '4.4.2',
                    'deviceName': '127.0.0.1:62001',
                    'appPackage': 'com.guokr.mentor',
                    'appActivity': '.ui.activity.MainActivity',
                    'unicodeKeyboard': True,
                    'resetKeyboard': True,
                    'noReset': True}
    driver = webdriver.Remote("http://localhost:4723/wd/hub", capabilities)
    myindex = IndexPage(driver)
    myindex.search()
